const express = require("express");
const axios = require("axios");
const qs = require("qs");
const request = require("request");
const router = express.Router();

router.post("/", (req,res, next)=>{
	let api = req.body.api;
	let params = Object.assign({},req.body);
	delete params.api;
	let headers = {
		token: req.session.token || "",
		uid: req.session.uid || ""
	};
	console.log(params);
	axios.post(api, params, {headers}).then(data=>{
		console.log(data);
		console.log(typeof(data));
		if(api == "/user/login" && data.code == "0"){
			console.log("good");
			req.session.token = data.result.token;
			req.session.uid = data.result.user.id;
			req.session.user = data.result.user;
			console.log(req.session);
		};
		res.send(data);
	});
});

module.exports = router;